﻿using UnityEngine;
using UniFrame.UI;
using System;

namespace UniFrame.Scene
{
    /// <summary>
    /// 场景状态基类
    /// </summary>
    public abstract class BaseScene
    {
        /// <summary>
        /// 默认画布名称
        /// </summary>
        public const string defaultCanvasName = "Canvas";
        /// <summary>
        /// 默认画布对象
        /// </summary>
        public GameObject defaultCanvas { get; private set; }
        /// <summary>
        /// 默认面板管理器
        /// </summary>
        public UIManager uIManager { get; private set; }
        /// <summary>
        /// 场景基类
        /// </summary>
        /// <param name="sceneName"></param>
        /// <param name="canvas"></param>
        public BaseScene(string sceneName,GameObject canvas = null)
        {
            SceneName = sceneName;
            defaultCanvas = canvas ?? GameObject.Find(defaultCanvasName);
        }
        /// <summary>
        /// 场景名称
        /// </summary>
        public string SceneName { get; private set; }
        /// <summary>
        /// 当场景进入时调用
        /// </summary>
        public virtual void OnSceneEnter()
        {
#if DEBUG
            Debug.LogFormat("DEBUG : On {0} Scene Enter ……",SceneName);
#endif
        }
        /// <summary>
        /// 当场景更新时调用
        /// </summary>
        public virtual void OnSceneUpdate()
        {
#if DEBUG
            Debug.LogFormat("DEBUG : On {0} Scene Update ……", SceneName);
#endif
        }
        /// <summary>
        /// 当场景退出时调用
        /// </summary>
        public virtual void OnSceneExit()
        {
#if DEBUG
            Debug.LogFormat("DEBUG : On {0} Scene Exit ……", SceneName);
#endif
        }
        /// <summary>
        /// 推入一个面板
        /// </summary>
        /// <param name="basePanel"></param>
        public void Push(BasePanel basePanel)
        {
            uIManager.Push(basePanel);
        }
        /// <summary>
        /// 弹出一个面板
        /// </summary>
        public void Pop()
        {
            uIManager.Pop();
        }

        internal void Initialize()
        {
            uIManager = new UIManager(defaultCanvas);
#if DEBUG
            Debug.LogFormat("DEBUG : On {0} Scene Initialize ……", SceneName);
#endif
        }
        internal void Release()
        {
            uIManager.DestroyAll();
#if DEBUG
            Debug.LogFormat("DEBUG : On {0} Scene Release ……", SceneName);
#endif
        }
    }
}
